import * as NS from "../../Common/NetServices";
import { IsNull } from "../../TYLibrary/Common/GlobalExtend";
import { Wx_XSPPage, T_Currency, V_Currency } from "../../Common/Entitys";
import { Log } from "../../TYLibrary/System/Logger";
import { WXDataClassRuntimeDecorator, Wx_PageData } from "../../Common/EntityBase";

@WXDataClassRuntimeDecorator()
class CurrencyPageData extends Wx_PageData {
    public Currency_TList: Array<V_Currency> = new Array<V_Currency>();
    public Currency_FList: Array<V_Currency> = new Array<V_Currency>();
    public Currency_TCount: number = 0;
    public Currency_FCount: number = 0;
    public tabIndex: number = 0;
    public selectdeFlag: boolean = false;
}

class CurrencyPage extends Wx_XSPPage {
    public Data: CurrencyPageData = new CurrencyPageData();

    /**
     * 初始化页面信息
     * @param {any} options
     * @returns {Promise<void>}
     * @memberof IndexPage
     */
    public async InitData(options: any): Promise<void> {
        try {
            let InfoFlag = false;
            let Info = options.Info;
            if (Info == "selectde") {
                InfoFlag = true;
            }
            this.Data.selectdeFlag = InfoFlag;
            let t = new Array<V_Currency>();
            let f = new Array<V_Currency>();

            this.App.CurrencyFList = await NS.QueryMemberTyCurrency(false);
            this.App.CurrencyTList = await NS.QueryMemberTyCurrency(true);

            if (this.App.CurrencyTList != null) {
                this.App.CurrencyTList.ForEach((item, index) => {
                    let c = item as V_Currency;
                    let stard = new Date(c.STARTTIME);
                    let endd = new Date(c.ENDTIME);
                    c.STARTDAY =
                        stard.getFullYear() + "." + (stard.getMonth() + 1) + "." + stard.getDate();
                    c.ENDDAY =
                        endd.getFullYear() + "." + (endd.getMonth() + 1) + "." + endd.getDate();
                    t.push(c);
                });
            }

            if (this.App.CurrencyFList != null) {
                this.App.CurrencyFList.ForEach((item, index) => {
                    let c = item as V_Currency;
                    let stard = new Date(c.STARTTIME);
                    let endd = new Date(c.ENDTIME);
                    c.STARTDAY =
                        stard.getFullYear() + "." + (stard.getMonth() + 1) + "." + stard.getDate();
                    c.ENDDAY =
                        endd.getFullYear() + "." + (endd.getMonth() + 1) + "." + endd.getDate();
                    f.push(c);
                });
            }

            this.Data.Currency_TList = t;
            this.Data.Currency_FList = f;
            this.Data.Currency_TCount = this.App.CurrencyTList.length;
            this.Data.Currency_FCount = this.App.CurrencyFList.length;
            this.Data.tabIndex = 0;
            this.Data.selectdeFlag = this.Data.selectdeFlag;
            this.Data.ApplyChange(this);
        } catch (e) {
            console.log(e);
        }
    }
}

Page(new CurrencyPage());
